﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TreeGraphicalControl;
using FeatureModelCore.Configuration;
using System.Windows.Controls;
using Collections.TreeCollections;
using System.Windows.Media;

namespace FeatureModelTool.ConfigGraphic
{
    public class TreeItem_ConfigNode : TreeViewItemControl
    {
        public ConfigNode ConfigInstance { get; protected set; }
        public TreeItem_ConfigNode(ConfigNode configNode)
        {
            ConfigInstance = configNode;

            ConfigRelationship r = (ConfigRelationship)configNode.Parent;
            if (r.Type == RelationshipConfigureType.Manadory)
            {
                this.Header = configNode.Name;
            }
            else if (r.Type == RelationshipConfigureType.Or
                || r.Type == RelationshipConfigureType.Optional)
            {
                CheckBox checkBox = new CheckBox();
                checkBox.Content = configNode.Name;

                this.Header = checkBox;
            }
            else if (r.Type == RelationshipConfigureType.Alternative)
            {
                RadioButton radioButton = new RadioButton();
                radioButton.Content = configNode.Name;
                radioButton.GroupName = r.ID.ToString();
                this.Header = radioButton;              
            }

            this.IsExpanded = true;
            this.Background = Brushes.Azure;
        }

        /// <summary>
        /// Tree Item Construct
        /// </summary>
        /// <param name="treeObj"></param>
        /// <returns></returns>
        public static TreeViewItemControl ConstructTreeItem(TreeObject treeObj)
        {
            ConfigNode configNode = treeObj as ConfigNode;
            if (configNode == null)
            {
                return null;
            }
            return new TreeItem_ConfigNode(configNode);
        }
        public static ContextMenu GenerateContext(TreeViewItemControl treeItem, TreeObject treeObj)
        {
            return null;
        }
    }
}
